$(function() {
	movie_index.run();
});

var movie_index = {
	run : function() {
		this._init_();
		this._start_();
		this._init_events();
	},

	_init_ : function() {
		this.itemUrl = "";
		this.title = "";		
		this.month = $("#month").val();		
	},

	_start_ : function() {
		$("#movie_side_ul > li").eq(2).addClass("curr");
		
		$("#month_div > a.initial").each(function(){
			var $this = $(this);
			var m = $this.attr("month");
			if(movie_index.month == m){
				$this.addClass("selected");
				return false;
			}
		});
	},

	_init_events : function() {
		this._bind_events();
		
		$("#movie_content_div > div.mi_box > div.img").bind({
			mouseenter:function(){
				$(this).children('div.tc_btn').fadeIn("slow");
			},
			mouseleave:function(){
				$(this).children('div.tc_btn').stop(true,false).fadeOut("fast");
			}
		});
	},

	_bind_events : function() {
		$("#month_div > a.initial").click(function() {
			var $this = $(this);			
			$("#month_div > a.initial").removeClass("selected");
			$this.addClass("selected");
			movie_index.month = $this.attr("month");			
			movie_index._query_movie();
			return false;
		});
	},

	_query_movie : function() {
		var url = main.contextPath + "/movie/movie2012/query?month=" + this.month;		
		$.get(url, function(result) {
			result = movie_index._bind_fly_image_events(result);
			$("#movie_content_div").html(result);			
		});
	},
	
	_bind_fly_image_events: function(result){
		var $div = $("<div>" + result + "</div>");
		$("div.mi_box > div.img", $div).bind({
			mouseenter:function(){
				$(this).children('div.tc_btn').fadeIn("slow");
			},
			mouseleave:function(){
				$(this).children('div.tc_btn').stop(true,false).fadeOut("fast");
			}
		});
		
		return $div.children();
	}
};